﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;

namespace BLL.SystemInformation
{
    [ServiceContract]
    class UCStaffAccountManage
    {
        //实例化数据层
        DAL.DALMethod myDAL = new DAL.DALMethod();
        //指示方法定义一个操作协定
        [OperationContract]
        //查询所有账号
        public DataSet SelectAllStaffAccount()
        {
            //声明对象数组
            SqlParameter[] parm =
            {
                new SqlParameter("@type",SqlDbType.VarChar),
            };
            //给对象数组赋值
            parm[0].Value = "UserControl_Loaded_SelectAllStaffAccount";
            //查询数据缓存
            return myDAL.QueryDataSet("UCStaffAccountManage",parm);
        }
        [OperationContract]
        //查询未分配权限操作员（下拉框）
        public DataSet SelectStaff()
        {
            //声明对象数组
            SqlParameter[] parm =
            {
                new SqlParameter("@type",SqlDbType.VarChar)
            };
            //给对象数组赋值
            parm[0].Value = "Window_Loaded_SelectStaff";
            //查询数据缓存
            return myDAL.QueryDataSet("UCStaffAccountManage", parm);
        }
        [OperationContract]
        //查询下拉框(权限组)
        public DataSet SelectPermissionGroup()
        {
            //声明对象数组
            SqlParameter[] parm =
            {
                new SqlParameter("@type",SqlDbType.VarChar)
            };
            //给对象数组赋值
            parm[0].Value = "Window_Loaded_SelectPermissionGroup";
            //查询数据缓存
            return myDAL.QueryDataSet("UCStaffAccountManage", parm);
        }
        /// <summary>
        /// 新增员工信息
        /// </summary>
        /// <param name="intPGroupID"></param>
        /// <param name="intStaffID"></param>
        /// <param name="strAccounts"></param>
        /// <param name="strPassword"></param>
        /// <param name="blEffective"></param>
        /// <param name="strNote"></param>
        /// <returns></returns>
        [OperationContract]
        public int InsertOperator(int intPGroupID, int intStaffID, string strAccounts, string strPassword, bool blEffective, string strNote)
        {
            //声明对象数组
            SqlParameter[] parm =
            {
                new SqlParameter("@type",SqlDbType.VarChar),
                new SqlParameter("@permissionGroupID",SqlDbType.Int),
                new SqlParameter("@staffID",SqlDbType.Int),
                new SqlParameter("@operatorAccounts",SqlDbType.VarChar),
                new SqlParameter("@operatorPassword",SqlDbType.VarChar),
                new SqlParameter("@effective",SqlDbType.Bit),
                new SqlParameter("@note",SqlDbType.VarChar)
            };
            //给对象数组赋值
            parm[0].Value = "btnSave_Click_InsertOperator";
            parm[1].Value = intPGroupID;
            parm[2].Value = intStaffID;
            parm[3].Value = strAccounts;
            parm[4].Value = strPassword;
            parm[5].Value = blEffective;
            parm[6].Value = strNote;
            //查询数据缓存
            return myDAL.UpdateData("UCStaffAccountManage", parm);
        }

        [OperationContract]
        //修改账号信息
        public int UpdateOperator(int intPGroupID, int intStaffID, string strAccounts, string strPassword, bool blEffective, string strNote, int intOperatorID)
        {
            //声明对象数组
            SqlParameter[] parm =
            {
                new SqlParameter("@type",SqlDbType.VarChar),
                new SqlParameter("@permissionGroupID",SqlDbType.Int),
                new SqlParameter("@staffID",SqlDbType.Int),
                new SqlParameter("@operatorAccounts",SqlDbType.VarChar),
                new SqlParameter("@operatorPassword",SqlDbType.VarChar),
                new SqlParameter("@effective",SqlDbType.Bit),
                new SqlParameter("@note",SqlDbType.VarChar),
                new SqlParameter("@operatorID",SqlDbType.Int)
            };
            //给对象数组赋值
            parm[0].Value = "btnSave_Click_UpdateOperator";
            parm[1].Value = intPGroupID;
            parm[2].Value = intStaffID;
            parm[3].Value = strAccounts;
            parm[4].Value = strPassword;
            parm[5].Value = blEffective;
            parm[6].Value = strNote;
            parm[7].Value = intOperatorID;
            //查询数据缓存
            return myDAL.UpdateData("UCStaffAccountManage", parm);
        }
        /// <summary>
        /// 删除账号信息
        /// </summary>
        [OperationContract]
        public int DeleteOperator(int intOperatorID)
        {
            //声明对象数组
            SqlParameter[] parm =
            {
                new SqlParameter("@type",SqlDbType.VarChar),
                new SqlParameter("@operatorID",SqlDbType.Int)
            };
            //给对象数组赋值
            parm[0].Value = "btnDelete_Click_DeleteOperator";
            parm[1].Value = intOperatorID;
            //查询数据缓存
            return myDAL.UpdateData("UCStaffAccountManage", parm);
        }
        //根据“姓名”获取staff_id
        [OperationContract]
        public DataSet btnSave_Click_SeleteStaffId(string strStaffName)
        {
            //1.0实例化对象数组(序列化参数)
            SqlParameter[] mySqlParameters = {
                //定义传递参数，以及传递参数的类型
                new SqlParameter("@type",SqlDbType.NChar),
                new SqlParameter("@staffName",SqlDbType.NVarChar),
            };
            //1.1 给对象赋值
            mySqlParameters[0].Value = "btnSave_Click_SeleteStaffId";
            mySqlParameters[1].Value = strStaffName;
            return myDAL.QueryDataSet("UCStaffAccountManage", mySqlParameters);
        }
        //根据“权限组”获取 permission_group_id        
        [OperationContract]
        public DataSet btnSave_Click_SeletePGroupId(string strPName)
        {
            //1.0实例化对象数组(序列化参数)
            SqlParameter[] mySqlParameters = {
                //定义传递参数，以及传递参数的类型
                new SqlParameter("@type",SqlDbType.NChar),
                new SqlParameter("@PGroupName",SqlDbType.NVarChar),
            };
            //1.1 给对象赋值
            mySqlParameters[0].Value = "btnSave_Click_SeletePGroupId";
            mySqlParameters[1].Value = strPName;
            return myDAL.QueryDataSet("UCStaffAccountManage", mySqlParameters);
        }

    }
}
